package cn.edu.stu.syllabus.utils;

import android.support.annotation.Nullable;

import java.util.List;

import cn.edu.stu.syllabus.base.BaseQuickClickAdapter;
import cn.edu.stu.syllabus.repository.oa.local.OaInfoEntry;

/**
 * Created by daidaijie on 2017/3/5.
 * 用于List的基本处理
 */

public class ListUtils {

    // Nullable 安全控制
    public static int getListSizeSafety(@Nullable List list) {
        return list == null ? 0 : list.size();
    }

    // 移动某项到头部
    public static void movePositionToTop(List list, int position) {
        if (getListSizeSafety(list) > 0) {
            Object object = list.get(position);
            list.remove(position);
            list.add(position, 0);
        }
    }

    // 移动某项到头部,配合Adpater
    public static void movePositionToTop(BaseQuickClickAdapter adapter, int position) {
        if (getListSizeSafety(adapter.getData()) > 0) {
            Object object = adapter.getItem(position);
            adapter.remove(position);
            adapter.add(0, object);
        }
    }
}
